************************************************************************
** Analysis of determinants of restrictions on human rights defenders **
** Bakke, Mitchell & Smidt (2019) **************************************
** Version 29.10.2019 ***************************************************
************************************************************************

version 13.0
set more off
clear
capture log close
log using "MainAnalyses_plusAppendices_log", replace

*net install clarify, from("HERE YOUR DIRECTORY WHERE YOU SAVED CLARIFY")

cd "HERE YOUR WORKING DIRECTORY WHERE YOU SAVED THE REPLOCATION FILES"
use RestrictionsFinalData.dta, clear

**********************
** Data preparation **
**********************

* Make time-series
tsset cowcode YEAR, yearly

* Labels
// define program
capture program drop labels
program labels
    label var pts_stateDep "PTS"
	label var ICCPR_ratif "ICCPR"
	label drop ICCPR_ratif
	label define ICCPR_ratif 0 "ICCPR not ratified" 1 "ICCPR ratified"
	label val ICCPR_ratif ICCPR_ratif
	label var conflictYear "Conflict year"
	label var polity2 "Polity IV Score"
	label var polity2_sq "Polity IV Score sq."
	label var exconst "Executive constraints"
	label var protest_ClarkRegan_logLag1 "Protest events (lag 1 year)"
	label var gdpPerCapita "GDP"
	label var gdpPerCapita_z "GDP (stand.)"
	label var population "Population size" 
	label var population_z "Population (stand.)" 
	label var youthBulgeln "Youth bulge"
	label var v2x_juconln "Independent judiciary"
	label var farissHumanRightsScores "Latent human rights abuses score"
	label var restrictionCount  "Count of restrictions"
	capture label var restrictionLag1 "Restrictions (lag 1 year)"
end

labels


******************************
** Main regression analysis **
******************************

**********
** Table 1
**********

set seed 1234

* Model 1A: ICCPR + PTS
xtnbreg restrictionCount2 c.pts_stateDep##i.ICCPR_ratif, corr(ar 1) pa
outreg2 using ".\Tables\Table1.doc", replace ctitle(Model 1A) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

* Model 1B: ICCPR + PTS
xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
outreg2 using ".\Tables\Table1.doc", append ctitle(Model 1B) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

* Figure 5
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(pts_stateDep) at(ICCPR_ratif =(0) ) atmeans
matrix table = r(table)
gen low = table[1,1] - 1.96*table[2,1] in 1
gen high = table[1,1] + 1.96*table[2,1] in 1
gen est = table[1,1] in 1
margins, dydx(pts_stateDep) at(ICCPR_ratif =(1) ) atmeans
matrix table = r(table)
matri list table
replace low = table[1,1] - 1.96*table[2,1] in 2
replace high = table[1,1] + 1.96*table[2,1] in 2
replace est = table[1,1] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "ICCPR not ratified" 2 "ICCPR ratified") xtitle("") yline(0) mcolor(gs10) msize(medlarge) ||
rcap low high x,  lcolor(gs10) lwidth(medthick) ytitle("Predicted effect of PTS on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Figure5.png", replace ;
#delimit cr


* Figure 6
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(ICCPR_ratif) at(pts_stateDep =(1) ) atmeans
matrix table = r(table)
matrix list table
gen low = table[1,2] - 1.96*table[2,2] in 1
gen high = table[1,2] + 1.96*table[2,2] in 1
gen est = table[1,2] in 1
margins, dydx(ICCPR_ratif) at(pts_stateDep =(5) ) atmeans
matrix table = r(table)
replace low = table[1,2] - 1.96*table[2,2] in 2
replace high = table[1,2] + 1.96*table[2,2] in 2
replace est = table[1,2] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5)) ysca(r(-0.5 0.5)) xlabel(1 "PTS low" 2 "PTS high") xtitle("") yline(0) mcolor(gs10) msize(medlarge) ||
rcap low high x,  lcolor(gs10) lwidth(medthick) ytitle("Predicted effect of ICCPR on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Figure6.png", replace ;
#delimit cr


* Figure 4
margins, predict(mu) at(pts_stateDep = (1(1)5) ICCPR_ratif =(0 1) ) atmeans
#delimit ;
marginsplot, xtitle("Political Terror Scale (PTS)") 
title("") recast(line)  
ytitle("Predicted number of restrictions") 
legend(label(3 "ICCPR not ratified") label(4 "ICCPR ratified")) legend(order(3 4))
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) 
plotopts(lwidth(medthick) lcolor(gs0)) 
recastci(rline) ciopts(lpattern(dash) lwidth(medthick) lcolor(gs0)) ;
gr_edit plotregion1.plot1.style.editstyle area(linestyle(color(gs10))) editcopy ;
gr_edit plotregion1.plot3.style.editstyle line(color(gs10)) editcopy ;
graph export ".\Figures\Figure4.png", replace ;
#delimit cr



** Model 2A: ICCPR + Fariss
xtgee restrictionCount2 c.farissHumanRightsScores##i.ICCPR_ratif if YEAR>=1994, iterate(1000) tol(0.01) force corr(ar 1) family(nbinom) link (nbinom) 
outreg2 using ".\Tables\Table1.doc", append ctitle(Model 2A) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

** Model 2B: ICCPR + Fariss
xtgee restrictionCount2 c.farissHumanRightsScores##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, iterate(1000) tol(0.01) force corr(ar 1) family(nbinom) link (nbinom) 
outreg2 using ".\Tables\Table1.doc", append ctitle(Model 2B) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')



** Model 3A: CAT + PTS
set seed 1234

xtnbreg restrictionCount2 c.pts_stateDep##i.CAT_ratif if YEAR>1994, corr(ar 1) pa
outreg2 using ".\Tables\Table2.doc", replace ctitle(Model 3A) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

** Model 3B: CAT + PTS
xtgee restrictionCount2 c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) force tol(0.01)
outreg2 using ".\Tables\Table2.doc", append ctitle(Model 3B) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

* Figure 8
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(pts_stateDep) at(CAT_ratif =(0) ) atmeans
matrix table = r(table)
gen low = table[1,1] - 1.96*table[2,1] in 1
gen high = table[1,1] + 1.96*table[2,1] in 1
gen est = table[1,1] in 1
margins, dydx(pts_stateDep) at(CAT_ratif =(1) ) atmeans
matrix table = r(table)
replace low = table[1,1] - 1.96*table[2,1] in 2
replace high = table[1,1] + 1.96*table[2,1] in 2
replace est = table[1,1] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "CAT not ratified" 2 "CAT ratified") xtitle("") yline(0) mcolor(gs10) msize(medlarge) ||
rcap low high x,  lcolor(gs10) lwidth(medthick) ytitle("Predicted effect of PTS on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Figure8.png", replace ;
#delimit cr


* Figure 9
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(CAT_ratif) at(pts_stateDep =(1) ) atmeans
matrix table = r(table)
gen low = table[1,2] - 1.96*table[2,2] in 1
gen high = table[1,2] + 1.96*table[2,2] in 1
gen est = table[1,2] in 1
margins, dydx(CAT_ratif) at(pts_stateDep =(5) ) atmeans
matrix table = r(table)
matrix list table
replace low = table[1,2] - 1.96*table[2,2] in 2
replace high = table[1,2] + 1.96*table[2,2] in 2
replace est = table[1,2] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5)) ylabel(-1.0 -0.5 0 0.5 1.0 1.5 2.0) xlabel(1 "PTS low" 2 "PTS high") xtitle("") yline(0) mcolor(gs10) msize(medlarge) ||
rcap low high x,  lcolor(gs10) lwidth(medthick) ytitle("Predicted effect of CAT on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Figure9.png", replace ;
#delimit cr


* Figure 7
margins, predict(mu) at(pts_stateDep = (1(1)5) CAT_ratif =(0 1) ) atmeans
#delimit ;
marginsplot, xtitle("Political Terror Scale (PTS)") 
title("")
ytitle("Predicted number of restrictions")
legend(label(1 "CAT not ratified") label(2 "CAT ratified")) legend(order(1 2))  
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) 
recast(line) plotopts(lwidth(medthick) lcolor(gs2)) 
recastci(rline) ciopts(lpattern(dash) lwidth(medthick) lcolor(gs2)) ;
gr_edit plotregion1.plot1.style.editstyle area(linestyle(color(gs10))) editcopy ;
gr_edit plotregion1.plot3.style.editstyle line(color(gs10)) editcopy ;
graph export ".\Figures\Figure7.png", replace ;
#delimit cr


** Model 4A: CAT and Farriss
xtgee restrictionCount2 c.farissHumanRightsScores##i.CAT_ratif if YEAR>1994, force corr(ar 1) family(nbinom) link (nbinom)  vce(robust)
outreg2 using ".\Tables\Table2.doc", append ctitle(Model 4A) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

** Model 4B: CAT and Farriss
xtgee restrictionCount2 c.farissHumanRightsScores##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) tol(0.02)
outreg2 using ".\Tables\Table2.doc", append ctitle(Model 4B) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')


**************************************************************************************
** TABLE 3: Estimate the marginal effects of all variable based on Model 1B
**************************************************************************************

set seed 1234

* ICCPR (Political Terror Scale = 1)
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
quietly: margins, at(ICCPR_ratif = 0 pts_stateDep=1) at(ICCPR_ratif = 1 pts_stateDep=1) atmeans post
test _b[1._at] = _b[2._at]
di "ICCPR (Political Terror Scale = 1): " _b[2._at] - _b[1._at] 

* ICCPR (Political Terror Scale = 5)
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
quietly: margins, at(ICCPR_ratif = 0 pts_stateDep=5) at(ICCPR_ratif = 1 pts_stateDep=5) atmeans post
test _b[1._at] = _b[2._at]
di "ICCPR (Political Terror Scale = 5): " _b[2._at] - _b[1._at]

* CAT (Political Terror Scale = 1)+
quietly: xtgee restrictionCount2 c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) force tol(0.01)
quietly: margins, at(pts_stateDep = 1 CAT_ratif=0) at(pts_stateDep = 1 CAT_ratif=1) atmeans post
test _b[1._at] = _b[2._at]
di "CAT (Political Terror Scale = 1)+: " _b[2._at] - _b[1._at]

* CAT (Political Terror Scale = 5)+
quietly: xtgee restrictionCount2 c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) force tol(0.01)
quietly: margins, at(pts_stateDep = 5 CAT_ratif=0) at(pts_stateDep = 5 CAT_ratif=1) atmeans post
test _b[1._at] = _b[2._at]
di "CAT (Political Terror Scale = 5)+: " _b[2._at] - _b[1._at]

* Political Terror Scale (ICCPR not ratified)
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
sum pts_stateDep
local mn = r(mean)
local mnsd = r(mean) + r(sd)
quietly: margins, at(pts_stateDep = `mn' ICCPR_ratif=0) at(pts_stateDep = `mnsd' ICCPR_ratif=0) atmeans post
test _b[1._at] = _b[2._at]
di "Political Terror Scale (ICCPR not ratified):" _b[2._at] - _b[1._at]

* Political Terror Scale (ICCPR ratified)
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
quietly: margins, at(pts_stateDep = `mn' ICCPR_ratif=1) at(pts_stateDep = `mnsd' ICCPR_ratif=1) atmeans post
test _b[1._at] = _b[2._at]
di "Political Terror Scale (ICCPR ratified):" _b[2._at] - _b[1._at]


* Political Terror Scale (CAT not ratified)+
quietly: xtgee restrictionCount2 c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) force tol(0.01)
sum pts_stateDep
local mn = r(mean)
local mnsd = r(mean) + r(sd)
quietly: margins, at(pts_stateDep = `mn' CAT_ratif=0) at(pts_stateDep = `mnsd' CAT_ratif=0) atmeans post
test _b[1._at] = _b[2._at]
di "Political Terror Scale (CAT not ratified)+:" _b[2._at] - _b[1._at]

* Political Terror Scale (CAT ratified)+
quietly: xtgee restrictionCount2 c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) force tol(0.01)
quietly: margins, at(pts_stateDep = `mn' CAT_ratif=1) at(pts_stateDep = `mnsd' CAT_ratif=1) atmeans post
test _b[1._at] = _b[2._at]
di "Political Terror Scale (CAT ratified)+:" _b[2._at] - _b[1._at]


* Protest events (lag 1 year)
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
sum protest_ClarkRegan_logLag1
local mn = r(mean)
local mnsd = r(mean) + r(sd)
quietly: margins, at(protest_ClarkRegan_logLag1 = `mn') at(protest_ClarkRegan_logLag1 = `mnsd') atmeans post
test _b[1._at] = _b[2._at]
di "Protest events (lag 1 year):"  _b[2._at] - _b[1._at]

* Executive constraints
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
sum exconst
local mn = r(mean)
local mnsd = r(mean) + r(sd)
quietly: margins, at(exconst = `mn') at(exconst = `mnsd') atmeans post
test _b[1._at] = _b[2._at]
di "Executive constraints:"  _b[2._at] - _b[1._at]

* Youth bulge
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
sum youthBulgeln
local mn = r(mean)
local mnsd = r(mean) + r(sd)
quietly: margins, at(youthBulgeln = `mn') at(youthBulgeln = `mnsd') atmeans post
test _b[1._at] = _b[2._at]
di "Youth bulge" _b[2._at] - _b[1._at]

* Independent judiciary
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
sum v2x_juconln
local mn = r(mean)
local mnsd = r(mean) + r(sd)
quietly: margins, at(v2x_juconln = `mn') at(v2x_juconln = `mnsd') atmeans post
test _b[1._at] = _b[2._at]
di "Independent judiciary:" _b[2._at] - _b[1._at]

* Conflict year
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
sum conflictYear
local mn = r(mean)
local mnsd = r(mean) + r(sd)
quietly: margins, at(conflictYear = `mn') at(conflictYear = `mnsd') atmeans post
test _b[1._at] = _b[2._at]
di "Conflict year:" _b[2._at] - _b[1._at]

* GDP (stand.)
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
sum gdpPerCapita_z
local mn = r(mean)
local mnsd = r(mean) + r(sd)
quietly: margins, at(gdpPerCapita_z = `mn') at(gdpPerCapita_z = `mnsd') atmeans post
test _b[1._at] = _b[2._at]
di "GDP (stand.):" _b[2._at] - _b[1._at]

* Population (stand.)
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
sum population_z
local mn = r(mean)
local mnsd = r(mean) + r(sd)
quietly: margins, at(population_z = `mn') at(population_z = `mnsd') atmeans post
test _b[1._at] = _b[2._at]
di "Population (stand.):" _b[2._at] - _b[1._at]


** SUBSTANTIVE INTERPRETATIONS IN THE TEXT

* "All else equal, ICCPR ratification among states that severely violate human rights (PTS=5) increases restrictions on civil society by roughly 0.784 types. 
*	The effect roughly corresponds to the effect of a 35 standard deviations-increase in protest events (about 170 events) or five standard deviations-increase in GDP per capita (about 64,178 constant U.S. dollars). 
*   CAT ratification among states that severely violate human rights (PTS=5) increases the average number of restriction types by 1.165 types.
*   This effect corresponds to the effect of a 53 standard deviations-increase in protest (about 258 events) and a 10 standard deviations-increase in GDP per capita (about 160,455 constant U.S. dollars)."
quietly: xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
gen sample = e(sample)
sum  protest_ClarkRegan_logLag1 if sample
gen  protest_ClarkRegan_logLag1_exp =  exp(protest_ClarkRegan_logLag1)
sum protest_ClarkRegan_logLag1_exp if sample

sum gdpPerCapita if sample
gen gdpPerCapita_exp = exp(gdpPerCapita)
sum gdpPerCapita_exp if sample


* "We examine our argument with a cross-national analysis of state-sponsored restrictions on civil society in 149 states between 1994 and 2014"
quietly: xtnbreg restrictionCount2 c.pts_stateDep##i.ICCPR_ratif, corr(ar 1) pa
gen sample = e(sample)

preserve
keep if restrictionCount2!=. & YEAR<=2014 & YEAR>=1994 // 176 unique countries
codebook cowcode
keep COUNTRY cowcode
duplicates drop cowcode, force
save sample1.dta, replace
restore

preserve
keep if sample // 149 unique countries
keep COUNTRY cowcode
duplicates drop cowcode, force
merge 1:1 cowcode using sample1.dta
tab COUNTRY if _merge==2
erase sample1.dta
restore

* "Comparing our measure with the V-Dem measure of repression of civil society and the CIRI freedom of association measures, we find that our data are quite highly but not perfectly correlated with both the V-Dem data (0.55, p-value = 0.00) and CIRI data (rho=0.52, p-value = 0.00)." 
pwcorr restrictionCount2 CSOgovRepress_ord, sig
pwcorr restrictionCount2 ciriHumanRights, sig


* "In the first year in our sample, 77 percent of the countries have ratified ICCPR, increasing over the period to 90 percent. Only 53 percent of the countries have ratified the CAT in the first year in our sample, increasing to 77 percent overall."
quietly xtnbreg restrictionCount2 c.pts_stateDep##i.ICCPR_ratif, corr(ar 1) pa

tab YEAR ICCPR_ratif if e(sample)==1, row
tab YEAR CAT_ratif if e(sample)==1, row





********************************
***** Summary stats table ******
********************************
quietly xtgee restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.1) force corr(ar 1) family(nbinom) link (nbinom)
drop if e(sample)!=1

#delimit ;
estpost summarize 
restrictionCount2
pts_stateDep 
farissHumanRightsScores
ICCPR_ratif 
CAT_ratif 
ICC_member
exconst 
youthBulge
v2x_jucon
protest_ClarkRegan_logLag1
conflictYear 
gdpPerCapita_z 
population_z ;
esttab using ".\Tables\TableSumStats.csv"
, cells("count mean sd min max")  label t(3)
plain replace; 
#delimit cr

** Figure 1: Please see R script "Figure1_MapRestrictions.R" ****


** Figure 2: Restrictions vs. PTS ***
capture gen num = 1
egen concat = concat(pts_stateDep restrictionCount)
egen nObs = total(num), by(concat)
sum nObs, d
capture drop nObs_cat
gen nObs_cat = 1 if nObs<=3
replace nObs_cat = 1.2 if nObs<=10 & nObs>3
replace nObs_cat = 1.5 if nObs<=25 & nObs>10
replace nObs_cat = 2 if nObs<=100 & nObs>25
replace nObs_cat = 3 if nObs<=250 & nObs>100
replace nObs_cat = 4 if nObs>250


#delimit ;
scatter restrictionCount pts_stateDep if nObs_cat==1, msize(*0.8) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount pts_stateDep if nObs_cat==1.2, msize(*1) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount pts_stateDep if nObs_cat==1.5, msize(*1.5) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount pts_stateDep if nObs_cat==2, msize(*2) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount pts_stateDep if nObs_cat==3, msize(*2.5) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount pts_stateDep if nObs_cat==4, msize(*3.5) mcolor(black) msymbol(circle_hollow)
legend(title("Number of" "observations", size(5) color(gs0)) label(1 "1-3") label(2 "4-10") label(3 "11-25") label(4 "26-100") label(5 "101-250") label(6 ">250") col(1) ring(1) pos(3))
yscale(r(-1 10))
xscale(r(0.5 5.5))
ylabel(0 1 2 3 4 5 6 7 8 9 10)
xlabel(1 2 3 4 5)
ytitle("Restriction count", size(5))
xtitle("Political Terror Scale (PTS)", size(5))
scheme(s3mono) graphregion(fcolor(white));
#delimit cr
graph export ".\Figures\Figure2.png", replace



** Figure 3: Restrictions vs. Fariss
_pctile farissHumanRightsScores, nq(5)
return list
gen fariss_cat = 1 if farissHumanRightsScores <= `r(r1)'
replace fariss_cat = 2 if farissHumanRightsScores > `r(r1)' & farissHumanRightsScores<=`r(r2)'
replace fariss_cat = 3 if farissHumanRightsScores >= `r(r2)' & farissHumanRightsScores<=`r(r3)'
replace fariss_cat = 4 if farissHumanRightsScores >= `r(r3)' & farissHumanRightsScores<=`r(r4)'
replace fariss_cat = 5 if farissHumanRightsScores >= `r(r4)'

capture drop concat
egen concat = concat(fariss_cat restrictionCount)
capture drop nObs
egen nObs = total(num), by(concat)
sum nObs, d
capture drop nObs_cat
gen nObs_cat = 1 if nObs<=3
replace nObs_cat = 1.2 if nObs<=10 & nObs>3
replace nObs_cat = 1.5 if nObs<=25 & nObs>10
replace nObs_cat = 2 if nObs<=100 & nObs>25
replace nObs_cat = 3 if nObs<=250 & nObs>100
replace nObs_cat = 4 if nObs>250

#delimit ;
scatter restrictionCount fariss_cat if nObs_cat==1, msize(*0.8) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount fariss_cat if nObs_cat==1.2, msize(*1) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount fariss_cat if nObs_cat==1.5, msize(*1.5) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount fariss_cat if nObs_cat==2, msize(*2) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount fariss_cat if nObs_cat==3, msize(*2.5) mcolor(black) msymbol(circle_hollow) ||
scatter restrictionCount fariss_cat if nObs_cat==4, msize(*3.5) mcolor(black) msymbol(circle_hollow)
legend(title("Number of" "observations", size(5) color(gs0)) label(1 "1-3") label(2 "4-10") label(3 "11-25") label(4 "26-100") label(5 "101-250") label(6 ">250") col(1) ring(1) pos(3))
yscale(r(-1 10))
xscale(r(0.5 5.5))
ylabel(0 1 2 3 4 5 6 7 8 9 10)
xlabel(1 "1st quant." 2 "2nd quant." 3 "3rd quant." 4 "4th quant." 5 "5th quant.")
ytitle("Restriction count", size(5))
xtitle("Latent human rights abuses score", size(5))
scheme(s3mono) graphregion(fcolor(white));
#delimit cr
graph export ".\Figures\Figure3.png", replace


exit

******************************************
******************************************
********** Appendices ********************
******************************************
******************************************


** Appendix C

* Make time-series
tsset cowcode YEAR, yearly
* Make lags and leads
sort cowcode YEAR
capture gen restrictionLag1 = 1L.restrictionCount
* Labels
labels
* Clear tsset and make survival analysis
tsset, clear
stset YEAR, id(cowcode) failure(ICCPR_ratif==1)

#delimit ;
stcox restrictionCount restrictionLag1  protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z, vce(robust) ;
estimates store m1; estat ic ; matrix OUT = r(S) ; local AIC =  OUT[1,5] ;
outreg2 using ".\Tables\Table_AppendixC.doc", replace symbol(**,*,+) ctitle(Model C1) label dec(3) addstat(AIC, `AIC', Log Likelihood, `e(ll)') eform;

stcox restrictionCount restrictionLag1 protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if pts_stateDep>=3, vce(robust) ;
estimates store m1; estat ic; matrix OUT = r(S); local AIC =  OUT[1,5] ;
outreg2 using ".\Tables\Table_AppendixC.doc", append symbol(**,*,+) ctitle(Model C2) label dec(3) addstat(AIC, `AIC', Log Likelihood, `e(ll)')  eform;
#delimit cr

stset YEAR, id(cowcode) failure(CAT_ratif==1)
#delimit ;
stcox restrictionCount restrictionLag protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z, vce(robust) ;
estimates store m1 ; estat ic ; matrix OUT = r(S) ; local AIC =  OUT[1,5] ;
outreg2 using ".\Tables\Table_AppendixC.doc", append symbol(**,*,+) ctitle(Model C3) label dec(3) addstat(AIC, `AIC', Log Likelihood, `e(ll)')  eform;

stcox restrictionCount restrictionLag1  protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if pts_stateDep>=3, vce(robust)  ;
estimates store m1; estat ic; matrix OUT = r(S); local AIC =  OUT[1,5] ;
outreg2 using ".\Tables\Table_AppendixC.doc", append symbol(**,*,+) ctitle(Model C4) label dec(3) addstat(AIC, `AIC', Log Likelihood, `e(ll)')  eform;
#delimit cr

stset, clear
xtset cowcode YEAR


** Appendix D
set seed 1234
xtnbreg restrictionCount2 c.pts_stateDep##i.ICCPR_ratif if YEAR>=2001, corr(ar 1) pa
outreg2 using ".\Tables\AppendixD1.doc", replace ctitle(Model D1) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=2001, corr(ar 1) pa
outreg2 using ".\Tables\AppendixD1.doc", append ctitle(Model D2) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.farissHumanRightsScores##i.ICCPR_ratif if YEAR>=2001, pa corr(ar 1)
outreg2 using ".\Tables\AppendixD1.doc", append ctitle(Model D3) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.farissHumanRightsScores##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=2001, corr(ar 1) pa
outreg2 using ".\Tables\AppendixD1.doc", append ctitle(Model D4) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.pts_stateDep##i.CAT_ratif if YEAR>1994, corr(ar 1) family(nbinom) link(nbinom)
outreg2 using ".\Tables\AppendixD2.doc", replace ctitle(Model D5) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=2001, pa corr(ar 1)
outreg2 using ".\Tables\AppendixD2.doc", append ctitle(Model D6) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.farissHumanRightsScores##i.CAT_ratif if YEAR>=2001, corr(ar 1) family(nbinom) link(nbinom) 
outreg2 using ".\Tables\AppendixD2.doc", append ctitle(Model D7) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.farissHumanRightsScores##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=2001, pa corr(ar 1)
outreg2 using ".\Tables\AppendixD2.doc", append ctitle(Model D8) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')


** Appendix E

* Pooled models
nbreg restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z, vce(cluster cowcode)
outreg2 using ".\Tables\AppendixE1.doc", replace ctitle(Model E1) label dec(3) symbol(**,*,+) addstat(Log Likelihood, `e(ll)')

nbreg restrictionCount2 c.farissHumanRightsScores##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z, vce(cluster cowcode)
outreg2 using ".\Tables\AppendixE1.doc", append ctitle(Model E2) label dec(3) symbol(**,*,+) addstat(Log Likelihood, `e(ll)')

nbreg restrictionCount2 c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst  v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z, vce(cluster cowcode)
outreg2 using ".\Tables\AppendixE1.doc", append ctitle(Model E3) label dec(3) symbol(**,*,+) addstat(Log Likelihood, `e(ll)')

nbreg restrictionCount2 c.farissHumanRightsScores##i.CAT_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z, vce(cluster cowcode)
outreg2 using ".\Tables\AppendixE1.doc", append ctitle(Model E4) label dec(3) symbol(**,*,+) addstat(Log Likelihood, `e(ll)')


* with RE
xtnbreg restrictionCount2 c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z, re
outreg2 using ".\Tables\AppendixE2.doc", replace ctitle(Model E5) label dec(3) symbol(**,*,+) addstat(Log Likelihood, `e(ll)')

xtnbreg restrictionCount2 c.farissHumanRightsScores##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z, re nrtol(0.001)
outreg2 using ".\Tables\AppendixE2.doc", append ctitle(Model E6) label dec(3) symbol(**,*,+) addstat(Log Likelihood, `e(ll)')

xtnbreg restrictionCount2 c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst  v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z, re nrtol(0.001)
outreg2 using ".\Tables\AppendixE2.doc", append ctitle(Model E7) label dec(3) symbol(**,*,+) addstat(Log Likelihood, `e(ll)')

xtnbreg restrictionCount2 c.farissHumanRightsScores##i.CAT_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z, re nrtol(0.001)
outreg2 using ".\Tables\AppendixE2.doc", append ctitle(Model E8) label dec(3) symbol(**,*,+) addstat(Log Likelihood, `e(ll)')



** Appendix F
capture drop anyTreaty
gen anyTreaty = ICCPR_ratif + CAT_ratif
replace anyTreaty=1 if anyTreaty>1

capture drop anyTreatyCount
gen anyTreatyCount = ICCPR_ratif+CAT_ratif

xtgee restrictionCount2 c.pts_stateDep##i.anyTreaty protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln  conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) force tol(0.01)
outreg2 using ".\Tables\AppendixTableF.doc", replace ctitle(Model F1) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.farissHumanRightsScores##i.anyTreaty protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) force tol(0.02)
outreg2 using ".\Tables\AppendixTableF.doc", append ctitle(Model F2) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.pts_stateDep##c.anyTreatyCount protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) force tol(0.015)
outreg2 using ".\Tables\AppendixTableF.doc", append ctitle(Model F3) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.farissHumanRightsScores##c.anyTreatyCount protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(nbinom) link(nbinom) force tol(0.1)
outreg2 using ".\Tables\AppendixTableF.doc", append ctitle(Model F4) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')



** Appendix G

xtgee CSOgovRepress_ord c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(binomial 5) link(logit) force
outreg2 using ".\Tables\AppendixTableG.doc", replace ctitle(Model G1) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee CSOgovRepress_ord c.farissHumanRightsScores##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(binomial 5) link(logit) force
outreg2 using ".\Tables\AppendixTableG.doc", append ctitle(Model G2) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee CSOgovRepress_ord c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(binomial 5) link(logit) force
outreg2 using ".\Tables\AppendixTableG.doc", append ctitle(Model G3) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee CSOgovRepress_ord c.farissHumanRightsScores##i.CAT_ratif protest_ClarkRegan_logLag1 exconst v2x_juconln youthBulgeln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) family(binomial 5) link(logit) force
outreg2 using ".\Tables\AppendixTableG.doc", append ctitle(Model G4) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')



** Appendix H
xtgee restrictionCount2 c.pts_stateDep##i.ICC_member if YEAR>=2002, force corr(ar 1) family(nbinom) link (nbinom) 
outreg2 using ".\Tables\AppendixTableH1.doc", replace ctitle(Model 5A) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.pts_stateDep##i.ICC_member protest_ClarkRegan_logLag1 v2x_juconln exconst youthBulgeln conflictYear gdpPerCapita_z population_z if YEAR>=2002, corr(ar 1) pa
outreg2 using ".\Tables\AppendixTableH1.doc", append ctitle(Model 5B) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

* Figure
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(pts_stateDep) at(ICC_member =(0) ) atmeans
matrix table = r(table)
gen low = table[1,1] - 1.96*table[2,1] in 1
gen high = table[1,1] + 1.96*table[2,1] in 1
gen est = table[1,1] in 1
margins, dydx(pts_stateDep) at(ICC_member =(1) ) atmeans
matrix table = r(table)
replace low = table[1,1] - 1.96*table[2,1] in 2
replace high = table[1,1] + 1.96*table[2,1] in 2
replace est = table[1,1] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "ICC not member" 2 "ICC member") xtitle("") yline(0) mcolor(eltblue) msize(medlarge) ||
rcap low high x,  lcolor(eltblue) lwidth(medthick) ytitle("Predicted effect of PTS on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Effect_ICC_PTS1_withWar.png", replace ;
#delimit cr

* Figure
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(ICC_member) at(pts_stateDep =(1) ) atmeans
matrix table = r(table)
gen low = table[1,2] - 1.96*table[2,2] in 1
gen high = table[1,2] + 1.96*table[2,2] in 1
gen est = table[1,2] in 1
margins, dydx(ICC_member) at(pts_stateDep =(5) ) atmeans
matrix table = r(table)
replace low = table[1,2] - 1.96*table[2,2] in 2
replace high = table[1,2] + 1.96*table[2,2] in 2
replace est = table[1,2] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "PTS low" 2 "PTS high") xtitle("") yline(0) mcolor(eltblue) msize(medlarge) ||
rcap low high x,  lcolor(eltblue) lwidth(medthick) ytitle("Predicted effect of ICC on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Effect_ICC_PTS2_withWar.png", replace ;
#delimit cr

* Figure
margins, predict(mu) at(pts_stateDep = (1(1)5) ICC_member =(0 1) ) atmeans
#delimit ;
marginsplot, xtitle("Political Terror Scale") 
title("") 
ytitle("Predicted number of restrictions") 
legend(label(1 "ICC not member") label(2 "ICC member")) legend(order(1 2)) 
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) 
recast(line) plotopts(lwidth(medthick) lcolor(gs2)) 
recastci(rline) ciopts(lpattern(dash) lwidth(medthick) lcolor(gs2)) ;
gr_edit plotregion1.plot1.style.editstyle area(linestyle(color(eltblue))) editcopy ;
gr_edit plotregion1.plot3.style.editstyle line(color(eltblue)) editcopy ;
graph export ".\Figures\Predictions_ICC_PTS_withWar.png", replace ;
#delimit cr

xtgee restrictionCount2 c.farissHumanRightsScores##i.ICC_member if YEAR>=2002, force corr(ar 1) family(nbinom) link (nbinom)
outreg2 using ".\Tables\AppendixTableH1.doc", append ctitle(Model 6A) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.farissHumanRightsScores##i.ICC_member protest_ClarkRegan_logLag1 v2x_juconln exconst conflictYear youthBulgeln gdpPerCapita_z population_z if YEAR>=2002, corr(ar 1) pa
outreg2 using ".\Tables\AppendixTableH1.doc", append ctitle(Model 6B) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

/* Figure
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(farissHumanRightsScores) at(ICC_member =(0) ) atmeans
matrix table = r(table)
gen low = table[1,1] - 1.96*table[2,1] in 1
gen high = table[1,1] + 1.96*table[2,1] in 1
gen est = table[1,1] in 1
margins, dydx(farissHumanRightsScores) at(ICC_member =(1) ) atmeans
matrix table = r(table)
replace low = table[1,1] - 1.96*table[2,1] in 2
replace high = table[1,1] + 1.96*table[2,1] in 2
replace est = table[1,1] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "ICC not member" 2 "ICC member") xtitle("") yline(0) mcolor(eltblue) msize(medlarge) ||
rcap low high x,  lcolor(eltblue) lwidth(medthick) ytitle("Predicted effect of latent abuses on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Effect_ICC_Fariss1_withWar.png", replace ;
#delimit cr

* Figure
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(ICC_member) at(farissHumanRightsScores =(-2) ) atmeans
matrix table = r(table)
gen low = table[1,2] - 1.96*table[2,2] in 1
gen high = table[1,2] + 1.96*table[2,2] in 1
gen est = table[1,2] in 1
margins, dydx(ICC_member) at(farissHumanRightsScores =(1) ) atmeans
matrix table = r(table)
matrix list table
replace low = table[1,2] - 1.96*table[2,2] in 2
replace high = table[1,2] + 1.96*table[2,2] in 2
replace est = table[1,2] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "ICC not member" 2 "ICC member") xtitle("") yline(0) mcolor(eltblue) msize(medlarge) ||
rcap low high x,  lcolor(eltblue) lwidth(medthick) ytitle("Predicted effect of latent abuses on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Effect_ICC_Fariss2_withWar.png", replace ;
#delimit cr

margins, predict(mu) at(farissHumanRightsScores = (-4(1)2) ICC_member =(0 1) ) atmeans
#delimit ;
marginsplot, xtitle("Fariss latent human rights scores") 
title("")
ytitle("Predicted number of restrictions") 
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) 
legend(label(1 "ICC not member") label(2 "ICC member")) legend(order(1 2)) 
recast(line) plotopts(lwidth(medthick) lcolor(gs2)) 
recastci(rline) ciopts(lpattern(dash) lwidth(medthick) lcolor(gs2)) ;
gr_edit plotregion1.plot1.style.editstyle area(linestyle(color(eltblue))) editcopy ;
gr_edit plotregion1.plot3.style.editstyle line(color(eltblue)) editcopy ;
graph export ".\Figures\Prediction_ICC_Fariss_withWar.png", replace ;
#delimit cr
*/


* Excluding war-torn states
xtgee restrictionCount2 c.pts_stateDep##i.ICC_member if conflictYear==0 & YEAR>=2002, force corr(ar 1) family(nbinom) link (nbinom) 
outreg2 using ".\Tables\AppendixTableH2.doc", replace ctitle(Model 5A) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.pts_stateDep##i.ICC_member protest_ClarkRegan_logLag1 v2x_juconln exconst youthBulgeln conflictYear gdpPerCapita_z population_z if conflictYear==0 & YEAR>=2002, force corr(ar 1) family(nbinom) link (nbinom) tol(0.001)
outreg2 using ".\Tables\AppendixTableH2.doc", append ctitle(Model 5B) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

* Figure
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(pts_stateDep) at(ICC_member =(0) ) atmeans
matrix table = r(table)
gen low = table[1,1] - 1.96*table[2,1] in 1
gen high = table[1,1] + 1.96*table[2,1] in 1
gen est = table[1,1] in 1
margins, dydx(pts_stateDep) at(ICC_member =(1) ) atmeans
matrix table = r(table)
replace low = table[1,1] - 1.96*table[2,1] in 2
replace high = table[1,1] + 1.96*table[2,1] in 2
replace est = table[1,1] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "ICC not member" 2 "ICC member") xtitle("") yline(0) mcolor(eltblue) msize(medlarge) ||
rcap low high x,  lcolor(eltblue) lwidth(medthick) ytitle("Predicted effect of PTS on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Effect_ICC_PTS1.png", replace ;
#delimit cr


* Figure
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(ICC_member) at(pts_stateDep =(1) ) atmeans
matrix table = r(table)
gen low = table[1,2] - 1.96*table[2,2] in 1
gen high = table[1,2] + 1.96*table[2,2] in 1
gen est = table[1,2] in 1
margins, dydx(ICC_member) at(pts_stateDep =(5) ) atmeans
matrix table = r(table)
replace low = table[1,2] - 1.96*table[2,2] in 2
replace high = table[1,2] + 1.96*table[2,2] in 2
replace est = table[1,2] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "PTS low" 2 "PTS high") xtitle("") yline(0) mcolor(eltblue) msize(medlarge) ||
rcap low high x,  lcolor(eltblue) lwidth(medthick) ytitle("Predicted effect of ICC on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Effect_ICC_PTS2.png", replace ;
#delimit cr


margins, predict(mu) at(pts_stateDep = (1(1)5) ICC_member =(0 1) ) atmeans
#delimit ;
marginsplot, xtitle("Political Terror Scale") 
title("") 
ytitle("Predicted number of restrictions") 
legend(label(1 "ICC not member") label(2 "ICC member")) legend(order(1 2)) 
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) 
recast(line) plotopts(lwidth(medthick) lcolor(gs2)) 
recastci(rline) ciopts(lpattern(dash) lwidth(medthick) lcolor(gs2)) ;
gr_edit plotregion1.plot1.style.editstyle area(linestyle(color(eltblue))) editcopy ;
gr_edit plotregion1.plot3.style.editstyle line(color(eltblue)) editcopy ;
graph export ".\Figures\Predictions_ICC_PTS.png", replace ;
#delimit cr


xtgee restrictionCount2 c.farissHumanRightsScores##i.ICC_member if conflictYear==0 & YEAR>=2002, force corr(ar 1) family(nbinom) link (nbinom)
outreg2 using ".\Tables\AppendixTableH2.doc", append ctitle(Model 6A) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.farissHumanRightsScores##i.ICC_member protest_ClarkRegan_logLag1 v2x_juconln exconst conflictYear youthBulgeln gdpPerCapita_z population_z if YEAR>=2002 & conflictYear==0, tol(0.01) force corr(ar 1) family(nbinom) link (nbinom)
outreg2 using ".\Tables\AppendixTableH2.doc", append ctitle(Model 6B) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')


* Delete "comment out" to run for Fariss data
/* Figure
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(farissHumanRightsScores) at(ICC_member =(0) ) atmeans
matrix table = r(table)
gen low = table[1,1] - 1.96*table[2,1] in 1
gen high = table[1,1] + 1.96*table[2,1] in 1
gen est = table[1,1] in 1
margins, dydx(farissHumanRightsScores) at(ICC_member =(1) ) atmeans
matrix table = r(table)
replace low = table[1,1] - 1.96*table[2,1] in 2
replace high = table[1,1] + 1.96*table[2,1] in 2
replace est = table[1,1] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "ICC not member" 2 "ICC member") xtitle("") yline(0) mcolor(eltblue) msize(medlarge) ||
rcap low high x,  lcolor(eltblue) lwidth(medthick) ytitle("Predicted effect of latent abuses on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Effect_ICC_Fariss1.png", replace ;
#delimit cr


* Figure
capture drop low 
capture drop high 
capture drop x 
capture drop est
margins, dydx(ICC_member) at(farissHumanRightsScores =(-2) ) atmeans
matrix table = r(table)
gen low = table[1,2] - 1.96*table[2,2] in 1
gen high = table[1,2] + 1.96*table[2,2] in 1
gen est = table[1,2] in 1
margins, dydx(ICC_member) at(farissHumanRightsScores =(1) ) atmeans
matrix table = r(table)
matrix list table
replace low = table[1,2] - 1.96*table[2,2] in 2
replace high = table[1,2] + 1.96*table[2,2] in 2
replace est = table[1,2] in 2
gen x = 1 in 1
replace x = 2 in 2
#delimit ;
twoway scatter est x, xsca(r(0.5 2.5))  xlabel(1 "ICC not member" 2 "ICC member") xtitle("") yline(0) mcolor(eltblue) msize(medlarge) ||
rcap low high x,  lcolor(eltblue) lwidth(medthick) ytitle("Predicted effect of latent abuses on restrictions") ||
scatter est x in 2, mcolor(gs0) msize(medlarge) ||
rcap low high x in 2, lcolor(gs0)  lwidth(medthick)
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) legend(off) ;
graph export ".\Figures\Effect_ICC_Fariss2.png", replace ;
#delimit cr


margins, predict(mu) at(farissHumanRightsScores = (-4(1)2) ICC_member =(0 1) ) atmeans
#delimit ;
marginsplot, xtitle("Fariss latent human rights scores") 
title("")
ytitle("Predicted number of restrictions") 
scheme(p2bar) graphregion(fcolor(white) lstyle(none)) 
legend(label(1 "ICC not member") label(2 "ICC nmember")) legend(order(1 2)) 
recast(line) plotopts(lwidth(medthick) lcolor(gs2)) 
recastci(rline) ciopts(lpattern(dash) lwidth(medthick) lcolor(gs2)) ;
gr_edit plotregion1.plot1.style.editstyle area(linestyle(color(eltblue))) editcopy ;
gr_edit plotregion1.plot3.style.editstyle line(color(eltblue)) editcopy ;
graph export ".\Figures\Prediction_ICC_Fariss.png", replace ;
#delimit cr

*/


** Appendix K
xtgee restrictionCount c.pts_stateDep##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.1) force corr(ar 1) family(nbinom) link (nbinom)
outreg2 using ".\Tables\AppendixTableK.doc", replace ctitle(Model K1) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount c.farissHumanRightsScores##i.ICCPR_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.1) force corr(ar 1) family(nbinom) link (nbinom)
outreg2 using ".\Tables\AppendixTableK.doc", append ctitle(Model K2) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount c.pts_stateDep##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.1) force corr(ar 1) family(nbinom) link (nbinom)
outreg2 using ".\Tables\AppendixTableK.doc", append ctitle(Model K3) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount c.farissHumanRightsScores##i.CAT_ratif protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.1) force corr(ar 1) family(nbinom) link (nbinom)
outreg2 using ".\Tables\AppendixTableK.doc", append ctitle(Model K4) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')



** Appendix M
set seed 1234

xtnbreg restrictionCount2 c.pts_stateDep_lag1##i.ICCPR_ratif_lag1 if YEAR>=1994, corr(ar 1) pa
outreg2 using ".\Tables\AppendixTableM1.doc", replace ctitle(Model M1) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.pts_stateDep_lag1##i.ICCPR_ratif_lag1 protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, tol(0.02) force corr(ar 1) family(nbinom) link (nbinom)
outreg2 using ".\Tables\AppendixTableM1.doc", append ctitle(Model M2) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.farissHumanRightsScores_lag1##i.ICCPR_ratif_lag1 if YEAR>=1994, iterate(1000) tol(0.01) force corr(ar 1) family(nbinom) link (nbinom) 
outreg2 using ".\Tables\AppendixTableM1.doc", append ctitle(Model M3) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtgee restrictionCount2 c.farissHumanRightsScores_lag1##i.ICCPR_ratif_lag1 protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, iterate(1000) tol(0.01) force corr(ar 1) family(nbinom) link (nbinom) 
outreg2 using ".\Tables\AppendixTableM1.doc", append ctitle(Model M4) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.pts_stateDep_lag1##i.CAT_ratif_lag1 if YEAR>1994, corr(ar 1) pa
outreg2 using ".\Tables\AppendixTableM2.doc", replace ctitle(Model M5) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.pts_stateDep_lag1##i.CAT_ratif_lag1 protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) pa
outreg2 using ".\Tables\AppendixTableM2.doc", append ctitle(Model M6) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.farissHumanRightsScores_lag1##i.CAT_ratif_lag1 if YEAR>1994, corr(ar 1) pa
outreg2 using ".\Tables\AppendixTableM2.doc", append ctitle(Model M7) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')

xtnbreg restrictionCount2 c.farissHumanRightsScores_lag1##i.CAT_ratif_lag1 protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z if YEAR>=1994, corr(ar 1) pa
outreg2 using ".\Tables\AppendixTableM2.doc", append ctitle(Model M8) label dec(3) symbol(**,*,+) addstat(Deviance, `e(deviance)')





** Appendix J

* Make time-series
tsset cowcode YEAR, yearly

* Correlation: V-Dem
pwcorr CSOgovRepress_ord restrictionCount2, sig

* Correlation: CIRI
pwcorr ciriRestrictAssembly restrictionCount2, sig


cd "C:\Users\smidt\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\temp"

qui summ CSOgovRepress_ord
gen CSOgovRepress_ord_n = (CSOgovRepress_ord - r(min)) / (r(max) - r(min))
	
qui summ restrictionCount2
gen restrictionCount2_n = (restrictionCount2 - r(min)) / (r(max) - r(min))

qui summ ciriRestrictAssembly
gen ciriRestrictAssembly_n = (ciriRestrictAssembly - r(min)) / (r(max) - r(min))


levelsof COUNTRY

* Countries with A
local country `" "Afghanistan" "Albania" "Algeria" "Angola" "Argentina" "Armenia" "Australia" "Austria" "Azerbaijan" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Afghanistan" "Albania" "Algeria" "Angola" "Argentina" "Armenia" "Australia" "Austria" "Azerbaijan"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_A1.tif", replace width(2550)

* Countries with B
local country `" "Bahamas" "Bahrain" "Bangladesh" "Barbados" "Belarus" "Belgium" "Belize" "Benin" "Bhutan" "Bolivia" "Bosnia-Herzegovina" "Botswana" "Brazil" "Brunei" "Bulgaria" "Burkina Faso (Upper Volta)" "Burundi" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Bahamas" "Bahrain" "Bangladesh" "Barbados" "Belarus" "Belgium" "Belize" "Benin" "Bhutan", col(3)
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_B1.png", replace width(2550)

gr combine "Bolivia" "Bosnia-Herzegovina" "Botswana" "Brazil" "Brunei" "Bulgaria" "Burkina Faso (Upper Volta)" "Burundi", col(3)
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_B2.png", replace width(2550)

* Countries with C
replace COUNTRY="Ivory Coast" if COUNTRY=="Cote D'lvoire"
local country `" "Cambodia (Kampuchea)" "Cameroon" "Canada" "Cape Verde" "Central African Republic" "Chad" "Chile" "China" "Colombia" "Comoros" "Congo" "Congo, Democratic Republic of" "Costa Rica" "Ivory Coast" "Croatia" "Cuba" "Cyprus" "Czech Republic" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Cambodia (Kampuchea)" "Cameroon" "Canada" "Cape Verde" "Central African Republic" "Chad" "Chile" "China" "Colombia", col(3)
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_C1.png", replace width(2550)

gr combine "Comoros" "Congo" "Congo, Democratic Republic of" "Costa Rica" "Ivory Coast" "Croatia" "Cuba" "Cyprus" "Czech Republic", col(3)
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_C2.png", replace width(2550)

* Countries with DE
local country `" "Denmark" "Djibouti" "Dominican Republic" "Ecuador" "Egypt" "El Salvador" "Equatorial Guinea" "Eritrea" "Estonia"  "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Denmark" "Djibouti" "Dominican Republic" "Ecuador" "Egypt" "El Salvador" "Equatorial Guinea" "Eritrea" "Estonia"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_DE1.png", replace width(2550)

* Countries with EFG
local country `" "Ethiopia" "Fiji" "Finland" "France" "Gabon" "Gambia" "Georgia" "Germany" "Ghana" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Ethiopia" "Fiji" "Finland" "France" "Gabon" "Gambia" "Georgia" "Germany" "Ghana"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_EFG1.png", replace width(2550)

* Countries with GHI
local country `" "Greece" "Guatemala" "Guinea" "Guinea-Bissau" "Guyana" "Haiti" "Honduras" "Hungary" "Iceland" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Greece" "Guatemala" "Guinea" "Guinea-Bissau" "Guyana" "Haiti" "Honduras" "Hungary" "Iceland"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_GHI1.png", replace width(2550)

* Countries with IJ
local country `" "India" "Indonesia" "Iran (Persia)" "Iraq" "Ireland" "Israel" "Italy" "Jamaica" "Japan" "' 
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "India" "Indonesia" "Iran (Persia)" "Iraq" "Ireland" "Israel" "Italy" "Jamaica" "Japan"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_IJ1.png", replace width(2550)

* Countries with JKL
replace COUNTRY = "North Korea" if COUNTRY=="Korea, People's Republic of"
replace COUNTRY = "South Korea" if COUNTRY=="Korea, Republic of"
local country `" "Jordan" "Kazakhstan" "Kenya" "North Korea" "South Korea" "Kosovo" "Kuwait" "Kyrgyz Republic" "Laos" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Jordan" "Kazakhstan" "Kenya" "North Korea" "South Korea" "Kosovo" "Kuwait" "Kyrgyz Republic" "Laos"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_JKL1.png", replace width(2550)

* Countries with LM
local country `" "Laos" "Latvia" "Lebanon" "Lesotho" "Liberia" "Libya" "Lithuania" "Luxembourg" "Macedonia (Former Yugoslavia)" "' 
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Laos" "Latvia" "Lebanon" "Lesotho" "Liberia" "Libya" "Lithuania" "Luxembourg" "Macedonia (Former Yugoslavia)" 
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_LM1.png", replace width(2550)

* Countries with M
local country `" "Madagascar (Malagasy)" "Malawi" "Malaysia" "Maldives" "Mali" "Malta" "Marshall Islands" "Mauritania" "Mauritius" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Madagascar (Malagasy)" "Malawi" "Malaysia" "Maldives" "Mali" "Malta" "Marshall Islands" "Mauritania" "Mauritius"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_M1.png", replace width(2550)

* Countries with M2
local country `" "Mexico" "Micronesia" "Moldova" "Monaco" "Mongolia" "Montenegro" "Morocco" "Mozambique" "Myanmar (Burma)" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Madagascar (Malagasy)" "Malawi" "Malaysia" "Maldives" "Mali" "Malta" "Marshall Islands" "Mauritania" "Mauritius"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_M2.png", replace width(2550)

* Countries with N
local country `" "Namibia" "Nepal" "Netherlands" "New Zealand" "Nicaragua" "Niger" "Nigeria" "Norway" "Oman" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Namibia" "Nepal" "Netherlands" "New Zealand" "Nicaragua" "Niger" "Nigeria" "Norway" "Oman"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_NO1.png", replace width(2550)

* Countries with P
local country `" "Pakistan" "Palau" "Panama" "Papua New Guinea" "Paraguay" "Peru" "Philippines" "Poland" "Portugal" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Pakistan" "Palau" "Panama" "Papua New Guinea" "Paraguay" "Peru" "Philippines" "Poland" "Portugal"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_P1.png", replace width(2550)

* countries with QRS
local country `" "Qatar" "Rumania" "Russia (Soviet Union)" "Rwanda" "Saudi Arabia" "Senegal" "Serbia" "Sierra Leone" "Singapore" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Qatar" "Rumania" "Russia (Soviet Union)" "Rwanda" "Saudi Arabia" "Senegal" "Serbia" "Sierra Leone" "Singapore"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_QS1.png", replace width(2550)

* Countries with S
local country `" "Slovakia" "Slovenia" "Solomon Islands" "Somalia" "South Africa" "South Sudan" "Spain" "Sri Lanka (Ceylon)" "Sudan" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Slovakia" "Slovenia" "Solomon Islands" "Somalia" "South Africa" "South Sudan" "Spain" "Sri Lanka (Ceylon)" "Sudan"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_S1.png", replace width(2550)

* Countries with ST
replace COUNTRY = "Tanzania" if COUNTRY=="Tanzania/Tanganyika"
local country `" "Surinam" "Swaziland" "Sweden" "Switzerland" "Syria" "Taiwan" "Tajikistan" "Tanzania" "Thailand" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Surinam" "Swaziland" "Sweden" "Switzerland" "Syria" "Taiwan" "Tajikistan" "Tanzania" "Thailand"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_ST1.png", replace width(2550)

* Countries with TU
local country `" "Timor-Leste" "Togo" "Trinidad and Tobago" "Tunisia" "Turkey" "Turkmenistan" "Uganda" "Ukraine" "United Arab Emirates" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "Timor-Leste" "Togo" "Trinidad and Tobago" "Tunisia" "Turkey" "Turkmenistan" "Uganda" "Ukraine" "United Arab Emirates"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_TU1.png", replace width(2550)

* Countries with UZ
local country `" "United Kingdom" "Uruguay" "Uzbekistan" "Venezuela" "Vietnam, Republic of" "Yemen" "Zambia" "Zimbabwe (Rhodesia)" "'
foreach lev of local country{
	twoway line CSOgovRepress_ord_n YEAR if COUNTRY=="`lev'", lwidth(0.5) || ///
	line ciriRestrictAssembly_n YEAR if COUNTRY=="`lev'", lwidth(0.5) lpattern("dash") || ///
	line restrictionCount2_n YEAR if COUNTRY=="`lev'", ///
	lwidth(1) yaxis(1) ytitle("", axis(1)) yscale(range(0) axis(1)) title("`lev'") ///
	legend(order (1 "V-Dem" 2 "CIRI" 3 "Our data")  symxsize(5) keygap(1) size(small) cols(3)) xtitle("") ylabel(0(0.2)1, axis(1)) scheme(s1mono) saving("`lev'", replace)
}
gr combine "United Kingdom" "Uruguay" "Uzbekistan" "Venezuela" "Vietnam, Republic of" "Yemen" "Zambia" "Zimbabwe (Rhodesia)"
graph export "C:\Users\hanna\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication\Figures\VDemOurData_UZ1.png", replace width(2550)


cd "C:\Users\smidt\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication"




** Appendix L1 and L2

*Jana von Stein
*STATA code for the maximum likelihood estimator used in Jana von Stein (jana.vonstein@vuw.ac.nz), 
*"Do Treaties Constrain or Screen? Selection Bias and Treaty Compliance" 

*****************************
*** L1: WITH PTS   **********
*****************************

version 13.0
set more off
clear

use RestrictionsFinalData.dta, clear


* Make time-series
tsset cowcode YEAR, yearly

labels

*---------------------------------------------------------------------------------------------------------------------------
sort cowcode YEAR
gen dummy = 0
by cowcode: replace dummy = 1 if ICCPR_ratif==1 & ICCPR_ratif[_n-1]==ICCPR_ratif


* Change here from 1 to 5
capture drop restrictionCount2_bi
gen restrictionCount2_bi = 1 if restrictionCount>=1
replace restrictionCount2_bi = 0 if restrictionCount<1

*Begin estimator 1
capture program drop biselect

program define biselect
version 7
    
	args lnf theta1 theta2 theta3 zrhoS zrhoN 

	tempvar rhoN rhoS 
	qui gen double `rhoN' = (exp(2*`zrhoN')-1) / (exp(2*`zrhoN')+1) 
	qui gen double `rhoS' = (exp(2*`zrhoS')-1) / (exp(2*`zrhoS')+1)

    quietly replace `lnf' = ln(($ML_y1==1)*binorm(`theta1',$ML_y2*`theta2', $ML_y2*`rhoS')+($ML_y1==0)*binorm(-`theta1',$ML_y3*`theta3', -$ML_y3*`rhoN'))

end

set matsize 150
capture drop y1
capture drop y2
capture drop y3
capture drop y1n

gen y1=ICCPR_ratif
gen y1n=-y1
gen y2=2*restrictionCount2_bi-1
gen y3=y2

local ivar1 "pts_stateDep protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z IGO_membership" 
local ivar2 "pts_stateDep protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z"
local ivar3 "pts_stateDep protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z"


prob y1 `ivar1' 
local ll1=e(ll)
qui matrix i1 = e(b)
qui matrix coleq i1 = eq1:

prob restrictionCount2_bi `ivar2' 
local ll2=e(ll)
qui matrix i2 = e(b)
qui matrix coleq i2 = eq2:
 
prob restrictionCount2_bi `ivar3' if y1==0
local ll3=e(ll)
qui matrix i3 = e(b)
qui matrix coleq i3 = eq3:

heckprob restrictionCount2_bi `ivar2', select (y1 = `ivar1') 
qui matrix i4 = e(b)
qui matrix rS=i4[1,"athrho:_cons"]
qui matrix coleq rS= eq4:

heckprob restrictionCount2_bi `ivar3', select (y1n = `ivar1')
qui matrix i5 = e(b)
qui matrix rN=-i5[1,"athrho:_cons"]
qui matrix coleq rN= eq5:

qui matrix initvec = i1,i2,i3,rS,rN

ml model lf biselect (y1 = `ivar1') (y2 = `ivar2') (y3 = `ivar3') () ()
ml init initvec, skip
ml search
ml maximize, difficult
est store est1
outreg2 est1 using ".\Tables\AppendixTableL1_L1.doc", replace ctitle(Model L1) label dec(3)

matrix list e(b)

*The coefficient on rhos (to be reported in tables, etc.) is:
disp (exp(2*[eq4]_cons)-1) / (exp(2*[eq4]_cons)+1)

*The coefficient on rhon (to be reported in tables, etc.) is:
disp (exp(2*[eq5]_cons)-1) / (exp(2*[eq5]_cons)+1)

*Are the constants in the two outcome equations equal?
test [eq2=eq3]:_cons

*Are the coefficients on a particular independent variable in the outcome equations equal?
test [eq2=eq3]: pts_stateDep

*End estimator 1


************************************************************;

**Calculating predicted probabilities**;
preserve
set seed 12345
drawnorm CR_b1-CR_b30, n(10000) means(e(b)) cov(e(V)) clear
save simulated_betas, replace
restore
	
merge using simulated_betas
drop _merge
	
postutil clear
	
postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi using sim , replace
    
noisily display "start"
	
local a=1
while `a' <= 5.0 {
 {
    
*Non-signatory means/modes;
quietly sum pts_stateDep if ICCPR_ratif==0	
scalar h_pts_stateDep=`r(mean)'
qui sum protest_ClarkRegan_logLag1 if ICCPR_ratif==0
scalar h_protest_ClarkRegan_logLag1=`r(mean)'
qui sum exconst if ICCPR_ratif==0	
scalar h_exconst=`r(mean)'
qui sum youthBulgeln if ICCPR_ratif==0
scalar h_youthBulgeln=`r(mean)'
qui sum v2x_juconln if ICCPR_ratif==0
scalar h_v2x_juconln=`r(mean)'
qui sum conflictYear if ICCPR_ratif==0
scalar h_conflictYear=`r(mean)'
qui sum gdpPerCapita_z if ICCPR_ratif==0
scalar h_gdpPerCapita_z=`r(mean)'
qui sum population_z if ICCPR_ratif==0
scalar h_population_z=`r(mean)'	
qui sum IGO_membership if ICCPR_ratif==0
scalar h_IGO_membership=`r(mean)'

#delimit ;
gen sel = CR_b1*`a' + CR_b2*h_protest_ClarkRegan_logLag1 + CR_b3*h_exconst + CR_b4*h_youthBulgeln 
+ CR_b5*h_v2x_juconln + CR_b6*h_conflictYear + CR_b7*h_gdpPerCapita_z + CR_b8*h_population_z + CR_b8*h_IGO_membership 
+ CR_b10*1;

sum sel;

gen psel = normprob(sel);
sum psel;
centile psel, centile(5.0,95.0);

gen outcome1a = CR_b11*`a' + CR_b12*h_protest_ClarkRegan_logLag1 + CR_b13*h_exconst + CR_b14*h_youthBulgeln 
+ CR_b15*h_v2x_juconln + CR_b16*h_conflictYear + CR_b17*h_gdpPerCapita_z + CR_b18*h_population_z  
+ CR_b19*1;

gen prob1 = normprob(outcome1a)*(1-psel);
sum prob1;
centile prob1, centile(5.0,95.0);

gen outcome1b = CR_b20*`a' + CR_b21*h_protest_ClarkRegan_logLag1 + CR_b22*h_exconst + CR_b23*h_youthBulgeln 
+ CR_b24*h_v2x_juconln + CR_b25*h_conflictYear + CR_b26*h_gdpPerCapita_z + CR_b27*h_population_z  
+ CR_b28*1;

gen prob0 = normprob(outcome1b)*(1-psel);
sum prob0;
centile prob0, centile(5.0,95.0);

gen diff=prob1-prob0;

gen diff_pts1_1 = prob1 if `a'==1;
gen diff_pts1_5 = prob1 if `a'==5;
gen diff_pts0_1 = prob0 if `a'==1;
gen diff_pts0_5 = prob0 if `a'==5;
    
gen diff1 = diff_pts1_5 - diff_pts1_1;
gen diff0 = diff_pts0_5 - diff_pts0_1;


egen probhat0=mean(prob0);
egen probhat1=mean(prob1);
egen diffhat=mean(diff);
    
egen diff1hat=mean(diff1);
egen diff0hat=mean(diff0);
	
tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi diff1_hat diff1_lo diff1_hi diff0_hat diff0_lo diff0_hi;  

_pctile prob0, p(5.0,95.0) ;
scalar `lo0' = r(r1);
scalar `hi0' = r(r2);  
    
_pctile prob1, p(5.0,95.0);
scalar `lo1'= r(r1);
scalar `hi1'= r(r2);  
    
_pctile diff, p(5.0,95.0);
    
scalar `diff_lo'= r(r1);
   
scalar `diff_hi'= r(r2);  

    
scalar `prob_hat0'=probhat0;
   
scalar `prob_hat1'=probhat1;
  
scalar `diff_hat'=diffhat;
    

post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') 
                (`diff_hat') (`diff_lo') (`diff_hi') ;

   
};      

drop sel outcome1a outcome1b psel prob0 prob1 diff probhat0 probhat1 diffhat ;
drop diff_pts1_1  diff_pts1_5 diff_pts0_1 diff_pts0_5 diff1 diff0 diff1hat diff0hat;
    
    
local a=`a'+ 1.0 ;
    
  
display "." _c;
    
} ;
	
postclose mypost;                                  

use sim, clear;

gen MV = (_n-1);

graph twoway line prob_hat1 MV, clwidth(medium) lcolor(black) clpattern(solid)
        ||   line lo1  MV, clpattern(dash) clwidth(thin) lcolor(black)
        ||   line hi1  MV, clpattern(dash) clwidth(thin) lcolor(black)
        ||   line prob_hat0 MV, clwidth(medium) lcolor(eltblue) lpattern(solid)
        ||   line lo0  MV, clpattern(dash) clwidth(thin) lcolor(eltblue)
        ||   line hi0  MV, clpattern(dash) clwidth(thin) lcolor(eltblue)
		|| ,   
            xlabel(, labsize(4)) 
            ylabel(, labsize(4))
            yscale(noline)
            xscale(noline)
            title("", size(3))
            subtitle("" "" " ", size(3))
            xtitle("Political Terror Scale", size(5)   )
            ytitle("Effect of ICCPR ratification", size(5))
            xsca(titlegap(2))
            ysca(titlegap(2))
            scheme(p2bar) graphregion(fcolor(white) lstyle(none)) 
			legend(label(4 "ICCPR not ratified") label(1 "ICCPR ratified") order(4 1));
graph export ".\Figures\Effect_ICCPR_SELECTION.png", replace ;

#delimit cr
*************************************************************;



*****************************
*** L1: WITH FARISS**********
*****************************

version 13.0
set more off
clear

use RestrictionsFinalData.dta, clear


* Make time-series
tsset cowcode YEAR, yearly

labels

*---------------------------------------------------------------------------------------------------------------------------

sort cowcode YEAR
gen dummy = 0
by cowcode: replace dummy = 1 if ICCPR_ratif==1 & ICCPR_ratif[_n-1]==ICCPR_ratif


* Change here from 1 to 5
capture drop restrictionCount2_bi
gen restrictionCount2_bi = 1 if restrictionCount>=1
replace restrictionCount2_bi = 0 if restrictionCount<1

*Begin estimator 1
capture program drop biselect

program define biselect
version 7
    
	args lnf theta1 theta2 theta3 zrhoS zrhoN 

	tempvar rhoN rhoS 
	qui gen double `rhoN' = (exp(2*`zrhoN')-1) / (exp(2*`zrhoN')+1) 
	qui gen double `rhoS' = (exp(2*`zrhoS')-1) / (exp(2*`zrhoS')+1)

    quietly replace `lnf' = ln(($ML_y1==1)*binorm(`theta1',$ML_y2*`theta2', $ML_y2*`rhoS')+($ML_y1==0)*binorm(-`theta1',$ML_y3*`theta3', -$ML_y3*`rhoN'))

end

set matsize 150
capture drop y1
capture drop y2
capture drop y3
capture drop y1n

gen y1=ICCPR_ratif
gen y1n=-y1
gen y2=2*restrictionCount2_bi-1
gen y3=y2

local ivar1 "farissHumanRightsScores protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z IGO_membership" 
local ivar2 "farissHumanRightsScores protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z"
local ivar3 "farissHumanRightsScores protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z"


prob y1 `ivar1' 
local ll1=e(ll)
qui matrix i1 = e(b)
qui matrix coleq i1 = eq1:

prob restrictionCount2_bi `ivar2' 
local ll2=e(ll)
qui matrix i2 = e(b)
qui matrix coleq i2 = eq2:
 
prob restrictionCount2_bi `ivar3' if y1==0
local ll3=e(ll)
qui matrix i3 = e(b)
qui matrix coleq i3 = eq3:

heckprob restrictionCount2_bi `ivar2', select (y1 = `ivar1') 
qui matrix i4 = e(b)
qui matrix rS=i4[1,"athrho:_cons"]
qui matrix coleq rS= eq4:

heckprob restrictionCount2_bi `ivar3', select (y1n = `ivar1')
qui matrix i5 = e(b)
qui matrix rN=-i5[1,"athrho:_cons"]
qui matrix coleq rN= eq5:

qui matrix initvec = i1,i2,i3,rS,rN

ml model lf biselect (y1 = `ivar1') (y2 = `ivar2') (y3 = `ivar3') () ()
ml init initvec, skip
ml search
ml maximize, difficult
est store est1
outreg2 est1 using ".\Tables\AppendixTableL1_L2.doc", replace ctitle(Model L2) label dec(3)
	
matrix list e(b)

*The coefficient on rhos (to be reported in tables, etc.) is:
disp (exp(2*[eq4]_cons)-1) / (exp(2*[eq4]_cons)+1)

*The coefficient on rhon (to be reported in tables, etc.) is:
disp (exp(2*[eq5]_cons)-1) / (exp(2*[eq5]_cons)+1)

*Are the constants in the two outcome equations equal?
test [eq2=eq3]:_cons

*Are the coefficients on a particular independent variable in the outcome equations equal?
test [eq2=eq3]: farissHumanRightsScores


*End estimator 1

*************************************************************;

**Calculating predicted probabilities**;

preserve
set seed 12345
drawnorm CR_b1-CR_b30, n(10000) means(e(b)) cov(e(V)) clear
save simulated_betas, replace
restore
	
merge using simulated_betas
drop _merge
	
postutil clear
	
postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi MV using sim , replace
    
noisily display "start"
	
local a=-2.5
while `a' <= 2.5 {
 {
    
*Non-signatory means/modes;
quietly sum farissHumanRightsScores if ICCPR_ratif==0	
scalar h_farissHumanRightsScores=`r(mean)'
qui sum protest_ClarkRegan_logLag1 if ICCPR_ratif==0
scalar h_protest_ClarkRegan_logLag1=`r(mean)'
qui sum exconst if ICCPR_ratif==0	
scalar h_exconst=`r(mean)'
qui sum youthBulgeln if ICCPR_ratif==0
scalar h_youthBulgeln=`r(mean)'
qui sum v2x_juconln if ICCPR_ratif==0
scalar h_v2x_juconln=`r(mean)'
qui sum conflictYear if ICCPR_ratif==0
scalar h_conflictYear=`r(mean)'
qui sum gdpPerCapita_z if ICCPR_ratif==0
scalar h_gdpPerCapita_z=`r(mean)'
qui sum population_z if ICCPR_ratif==0
scalar h_population_z=`r(mean)'	
qui sum IGO_membership if ICCPR_ratif==0
scalar h_IGO_membership=`r(mean)'

#delimit ;
gen sel = CR_b1*`a' + CR_b2*h_protest_ClarkRegan_logLag1 + CR_b3*h_exconst + CR_b4*h_youthBulgeln 
+ CR_b5*h_v2x_juconln + CR_b6*h_conflictYear + CR_b7*h_gdpPerCapita_z + CR_b8*h_population_z + CR_b8*h_IGO_membership 
+ CR_b10*1;

sum sel;

gen psel = normprob(sel);
sum psel;
centile psel, centile(5.0,95.0);

gen outcome1a = CR_b11*`a' + CR_b12*h_protest_ClarkRegan_logLag1 + CR_b13*h_exconst + CR_b14*h_youthBulgeln 
+ CR_b15*h_v2x_juconln + CR_b16*h_conflictYear + CR_b17*h_gdpPerCapita_z + CR_b18*h_population_z  
+ CR_b19*1;

gen prob1 = normprob(outcome1a)*(1-psel);
sum prob1;
centile prob1, centile(5.0,95.0);

gen outcome1b = CR_b20*`a' + CR_b21*h_protest_ClarkRegan_logLag1 + CR_b22*h_exconst + CR_b23*h_youthBulgeln 
+ CR_b24*h_v2x_juconln + CR_b25*h_conflictYear + CR_b26*h_gdpPerCapita_z + CR_b27*h_population_z  
+ CR_b28*1;

gen prob0 = normprob(outcome1b)*(1-psel);
sum prob0;
centile prob0, centile(5.0,95.0);

gen diff=prob1-prob0;

gen diff_pts1_1 = prob1 if `a'==1;
gen diff_pts1_5 = prob1 if `a'==5;
gen diff_pts0_1 = prob0 if `a'==1;
gen diff_pts0_5 = prob0 if `a'==5;
    
gen diff1 = diff_pts1_5 - diff_pts1_1;
gen diff0 = diff_pts0_5 - diff_pts0_1;


egen probhat0=mean(prob0);
egen probhat1=mean(prob1);
egen diffhat=mean(diff);
    
egen diff1hat=mean(diff1);
egen diff0hat=mean(diff0);
	
tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi MV diff1_hat diff1_lo diff1_hi diff0_hat diff0_lo diff0_hi;  

_pctile prob0, p(5.0,95.0) ;
scalar `lo0' = r(r1);
scalar `hi0' = r(r2);  
    
_pctile prob1, p(5.0,95.0);
scalar `lo1'= r(r1);
scalar `hi1'= r(r2);  
    
_pctile diff, p(5.0,95.0);
    
scalar `diff_lo'= r(r1);
   
scalar `diff_hi'= r(r2);  

    
scalar `prob_hat0'=probhat0;
   
scalar `prob_hat1'=probhat1;
  
scalar `diff_hat'=diffhat;
    
scalar `MV' = `a';
	
post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') 
                (`diff_hat') (`diff_lo') (`diff_hi') (`MV') ;

   
};      




drop sel outcome1a outcome1b psel prob0 prob1 diff probhat0 probhat1 diffhat ;
drop diff_pts1_1  diff_pts1_5 diff_pts0_1 diff_pts0_5 diff1 diff0 diff1hat diff0hat;
    
    
local a=`a'+ 0.5 ;
    
  
display "." _c;
    
} ;

	
postclose mypost;                                  

	
use sim, clear;


*gen MV = (_n-1)/100;

graph twoway line prob_hat1 MV, clwidth(medium) lcolor(black) clpattern(solid)
        ||   line lo1  MV, clpattern(dash) clwidth(thin) lcolor(black)
        ||   line hi1  MV, clpattern(dash) clwidth(thin) lcolor(black)
        ||   line prob_hat0 MV, clwidth(medium) lcolor(eltblue) lpattern(solid)
        ||   line lo0  MV, clpattern(dash) clwidth(thin) lcolor(eltblue)
        ||   line hi0  MV, clpattern(dash) clwidth(thin) lcolor(eltblue)
		|| ,   
            xlabel(, labsize(4)) 
            ylabel(, labsize(4))
            yscale(noline)
            xscale(noline)
            title("", size(3))
            subtitle("" "" " ", size(3))
            xtitle("Fariss' human rights abuses scores", size(5)   )
            ytitle("Effect of ICCPR ratification", size(5))
            xsca(titlegap(2))
            ysca(titlegap(2))
            scheme(p2bar) graphregion(fcolor(white) lstyle(none)) 
			legend(label(4 "ICCPR not ratified") label(1 "ICCPR ratified") order(4 1));
graph export ".\Figures\Effect_ICCPR_fariss_SELECTION.png", replace ;
#delimit cr
*************************************************************;




*****************************
*** L2: WITH PTS   **********
*****************************


version 13.0
set more off
clear

cd "C:\Users\smidt\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication"
use RestrictionsFinalData.dta, clear

* Make time-series
tsset cowcode YEAR, yearly

* Labels
labels


* Make time-series
tsset cowcode YEAR, yearly

labels

sort cowcode YEAR
gen dummy = 0
by cowcode: replace dummy = 1 if CAT_ratif==1 & CAT_ratif[_n-1]==CAT_ratif


* Change here from 1 to 5
capture drop restrictionCount2_bi
gen restrictionCount2_bi = 1 if restrictionCount>=1
replace restrictionCount2_bi = 0 if restrictionCount<1

*Begin estimator 1
capture program drop biselect

program define biselect
version 7
    
	args lnf theta1 theta2 theta3 zrhoS zrhoN 

	tempvar rhoN rhoS 
	qui gen double `rhoN' = (exp(2*`zrhoN')-1) / (exp(2*`zrhoN')+1) 
	qui gen double `rhoS' = (exp(2*`zrhoS')-1) / (exp(2*`zrhoS')+1)

    quietly replace `lnf' = ln(($ML_y1==1)*binorm(`theta1',$ML_y2*`theta2', $ML_y2*`rhoS')+($ML_y1==0)*binorm(-`theta1',$ML_y3*`theta3', -$ML_y3*`rhoN'))

end

set matsize 150
capture drop y1
capture drop y2
capture drop y3
capture drop y1n

gen y1=CAT_ratif
gen y1n=-y1
gen y2=2*restrictionCount2_bi-1
gen y3=y2

local ivar1 "pts_stateDep protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z IGO_membership" 
local ivar2 "pts_stateDep protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z"
local ivar3 "pts_stateDep protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z"


prob y1 `ivar1' 
local ll1=e(ll)
qui matrix i1 = e(b)
qui matrix coleq i1 = eq1:

prob restrictionCount2_bi `ivar2' 
local ll2=e(ll)
qui matrix i2 = e(b)
qui matrix coleq i2 = eq2:
 
prob restrictionCount2_bi `ivar3' if y1==0
local ll3=e(ll)
qui matrix i3 = e(b)
qui matrix coleq i3 = eq3:

heckprob restrictionCount2_bi `ivar2', select (y1 = `ivar1') 
qui matrix i4 = e(b)
qui matrix rS=i4[1,"athrho:_cons"]
qui matrix coleq rS= eq4:

heckprob restrictionCount2_bi `ivar3', select (y1n = `ivar1')
qui matrix i5 = e(b)
qui matrix rN=-i5[1,"athrho:_cons"]
qui matrix coleq rN= eq5:

qui matrix initvec = i1,i2,i3,rS,rN

ml model lf biselect (y1 = `ivar1') (y2 = `ivar2') (y3 = `ivar3') () ()
ml init initvec, skip
ml search
ml maximize, difficult
est store est1
outreg2 est1 using ".\Tables\AppendixTableL2_L3.doc", replace ctitle(Model L3) label dec(3)

matrix list e(b)

*The coefficient on rhos (to be reported in tables, etc.) is:
disp (exp(2*[eq4]_cons)-1) / (exp(2*[eq4]_cons)+1)

*The coefficient on rhon (to be reported in tables, etc.) is:
disp (exp(2*[eq5]_cons)-1) / (exp(2*[eq5]_cons)+1)

*Are the constants in the two outcome equations equal?
test [eq2=eq3]:_cons

*Are the coefficients on a particular independent variable in the outcome equations equal?
test [eq2=eq3]: pts_stateDep

*End estimator 1

*************************************************************;

**Calculating predicted probabilities**;
	
preserve
set seed 12345
drawnorm CR_b1-CR_b30, n(10000) means(e(b)) cov(e(V)) clear
save simulated_betas, replace
restore
	
merge using simulated_betas
drop _merge
	
postutil clear
	
postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi using sim , replace
    
noisily display "start"
	
local a=1
while `a' <= 5.0 {
 {
    
*Non-signatory means/modes;
quietly sum pts_stateDep if CAT_ratif==0	
scalar h_pts_stateDep=`r(mean)'
qui sum protest_ClarkRegan_logLag1 if CAT_ratif==0
scalar h_protest_ClarkRegan_logLag1=`r(mean)'
qui sum exconst if CAT_ratif==0	
scalar h_exconst=`r(mean)'
qui sum youthBulgeln if CAT_ratif==0
scalar h_youthBulgeln=`r(mean)'
qui sum v2x_juconln if CAT_ratif==0
scalar h_v2x_juconln=`r(mean)'
qui sum conflictYear if CAT_ratif==0
scalar h_conflictYear=`r(mean)'
qui sum gdpPerCapita_z if CAT_ratif==0
scalar h_gdpPerCapita_z=`r(mean)'
qui sum population_z if CAT_ratif==0
scalar h_population_z=`r(mean)'	
qui sum IGO_membership if CAT_ratif==0
scalar h_IGO_membership=`r(mean)'

#delimit ;
gen sel = CR_b1*`a' + CR_b2*h_protest_ClarkRegan_logLag1 + CR_b3*h_exconst + CR_b4*h_youthBulgeln 
+ CR_b5*h_v2x_juconln + CR_b6*h_conflictYear + CR_b7*h_gdpPerCapita_z + CR_b8*h_population_z + CR_b8*h_IGO_membership 
+ CR_b10*1;

sum sel;

gen psel = normprob(sel);
sum psel;
centile psel, centile(5.0,95.0);

gen outcome1a = CR_b11*`a' + CR_b12*h_protest_ClarkRegan_logLag1 + CR_b13*h_exconst + CR_b14*h_youthBulgeln 
+ CR_b15*h_v2x_juconln + CR_b16*h_conflictYear + CR_b17*h_gdpPerCapita_z + CR_b18*h_population_z  
+ CR_b19*1;

gen prob1 = normprob(outcome1a)*(1-psel);
sum prob1;
centile prob1, centile(5.0,95.0);

gen outcome1b = CR_b20*`a' + CR_b21*h_protest_ClarkRegan_logLag1 + CR_b22*h_exconst + CR_b23*h_youthBulgeln 
+ CR_b24*h_v2x_juconln + CR_b25*h_conflictYear + CR_b26*h_gdpPerCapita_z + CR_b27*h_population_z  
+ CR_b28*1;

gen prob0 = normprob(outcome1b)*(1-psel);
sum prob0;
centile prob0, centile(5.0,95.0);

gen diff=prob1-prob0;
    
egen probhat0=mean(prob0);
egen probhat1=mean(prob1);
egen diffhat=mean(diff);
    
tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi ;  

_pctile prob0, p(5.0,95.0) ;
scalar `lo0' = r(r1);
scalar `hi0' = r(r2);  
    
_pctile prob1, p(5.0,95.0);
scalar `lo1'= r(r1);
scalar `hi1'= r(r2);  
    
_pctile diff, p(5.0,95.0);
    
scalar `diff_lo'= r(r1);
   
 scalar `diff_hi'= r(r2);  

    
scalar `prob_hat0'=probhat0;
   
scalar `prob_hat1'=probhat1;
  
scalar `diff_hat'=diffhat;
    
   
post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') 
                (`diff_hat') (`diff_lo') (`diff_hi') ;

};      
    
    
drop sel outcome1a outcome1b psel prob0 prob1 diff probhat0 probhat1 diffhat ;
    
    
local a=`a'+ 1.0 ;
    
  
display "." _c;
    
} ;

	
postclose mypost;                                  

	
use sim, clear;


gen MV = (_n-1)/100;

	
graph twoway line prob_hat1 MV, clwidth(medium) lcolor(black) clpattern(solid)
        ||   line lo1  MV, clpattern(dash) clwidth(thin) lcolor(black)
        ||   line hi1  MV, clpattern(dash) clwidth(thin) lcolor(black)
        ||   line prob_hat0 MV, clwidth(medium) lcolor(eltblue) lpattern(solid)
        ||   line lo0  MV, clpattern(dash) clwidth(thin) lcolor(eltblue)
        ||   line hi0  MV, clpattern(dash) clwidth(thin) lcolor(eltblue)
		|| ,   
            xlabel(, labsize(4)) 
            ylabel(, labsize(4))
            yscale(noline)
            xscale(noline)
            title("", size(3))
            subtitle("" "" " ", size(3))
            xtitle("Political Terror Scale", size(5)   )
            ytitle("Effect of CAT ratification", size(5))
            xsca(titlegap(2))
            ysca(titlegap(2))
            scheme(p2bar) graphregion(fcolor(white) lstyle(none))
			legend(label(4 "CAT not ratified") label(1 "CAT ratified") order(4 1)) ;
graph export ".\Figures\Effect_CAT_SELECTION.png", replace ;
#delimit cr
*************************************************************;





*****************************
*** L2: WITH FARISS**********
*****************************

version 13.0
set more off
clear

cd "C:\Users\smidt\Dropbox\PC\Documents\PaperProjects\Paper-Cracking Down on HR defenders\Analysis\Code\Replication"
use RestrictionsFinalData.dta, clear

* Make time-series
tsset cowcode YEAR, yearly

* Labels
labels


*---------------------------------------------------------------------------------------------------------------------------

sort cowcode YEAR
gen dummy = 0
by cowcode: replace dummy = 1 if CAT_ratif==1 & CAT_ratif[_n-1]==CAT_ratif


* Change here from 1 to 5
capture drop restrictionCount2_bi
gen restrictionCount2_bi = 1 if restrictionCount>=1
replace restrictionCount2_bi = 0 if restrictionCount<1

*Begin estimator 1
capture program drop biselect

program define biselect
version 7
    
	args lnf theta1 theta2 theta3 zrhoS zrhoN 

	tempvar rhoN rhoS 
	qui gen double `rhoN' = (exp(2*`zrhoN')-1) / (exp(2*`zrhoN')+1) 
	qui gen double `rhoS' = (exp(2*`zrhoS')-1) / (exp(2*`zrhoS')+1)

    quietly replace `lnf' = ln(($ML_y1==1)*binorm(`theta1',$ML_y2*`theta2', $ML_y2*`rhoS')+($ML_y1==0)*binorm(-`theta1',$ML_y3*`theta3', -$ML_y3*`rhoN'))

end

set matsize 150
capture drop y1
capture drop y2
capture drop y3
capture drop y1n

gen y1=CAT_ratif
gen y1n=-y1
gen y2=2*restrictionCount2_bi-1
gen y3=y2

local ivar1 "farissHumanRightsScores protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z IGO_membership" 
local ivar2 "farissHumanRightsScores protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z"
local ivar3 "farissHumanRightsScores protest_ClarkRegan_logLag1 exconst youthBulgeln v2x_juconln conflictYear gdpPerCapita_z population_z"


prob y1 `ivar1' 
local ll1=e(ll)
qui matrix i1 = e(b)
qui matrix coleq i1 = eq1:

prob restrictionCount2_bi `ivar2' 
local ll2=e(ll)
qui matrix i2 = e(b)
qui matrix coleq i2 = eq2:
 
prob restrictionCount2_bi `ivar3' if y1==0
local ll3=e(ll)
qui matrix i3 = e(b)
qui matrix coleq i3 = eq3:

heckprob restrictionCount2_bi `ivar2', select (y1 = `ivar1') 
qui matrix i4 = e(b)
qui matrix rS=i4[1,"athrho:_cons"]
qui matrix coleq rS= eq4:

heckprob restrictionCount2_bi `ivar3', select (y1n = `ivar1')
qui matrix i5 = e(b)
qui matrix rN=-i5[1,"athrho:_cons"]
qui matrix coleq rN= eq5:

qui matrix initvec = i1,i2,i3,rS,rN

ml model lf biselect (y1 = `ivar1') (y2 = `ivar2') (y3 = `ivar3') () ()
ml init initvec, skip
ml search
ml maximize, difficult
est store est1
outreg2 est1 using ".\Tables\AppendixTableL2_L4.doc", replace ctitle(Model L4) label dec(3)
	
matrix list e(b)

*The coefficient on rhos (to be reported in tables, etc.) is:
disp (exp(2*[eq4]_cons)-1) / (exp(2*[eq4]_cons)+1)

*The coefficient on rhon (to be reported in tables, etc.) is:
disp (exp(2*[eq5]_cons)-1) / (exp(2*[eq5]_cons)+1)

*Are the constants in the two outcome equations equal?
test [eq2=eq3]:_cons

*Are the coefficients on a particular independent variable in the outcome equations equal?
test [eq2=eq3]: farissHumanRightsScores


*End estimator 1


*************************************************************;
**Calculating predicted probabilities**;

preserve
set seed 12345
drawnorm CR_b1-CR_b30, n(10000) means(e(b)) cov(e(V)) clear
save simulated_betas, replace
restore
	
merge using simulated_betas
drop _merge
	
postutil clear
	
postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi MV using sim , replace
    
noisily display "start"
	
local a=-2.5
while `a' <= 2.5 {
 {
    
*Non-signatory means/modes;
quietly sum farissHumanRightsScores if CAT_ratif==0	
scalar h_farissHumanRightsScores=`r(mean)'
qui sum protest_ClarkRegan_logLag1 if CAT_ratif==0
scalar h_protest_ClarkRegan_logLag1=`r(mean)'
qui sum exconst if CAT_ratif==0	
scalar h_exconst=`r(mean)'
qui sum youthBulgeln if CAT_ratif==0
scalar h_youthBulgeln=`r(mean)'
qui sum v2x_juconln if CAT_ratif==0
scalar h_v2x_juconln=`r(mean)'
qui sum conflictYear if CAT_ratif==0
scalar h_conflictYear=`r(mean)'
qui sum gdpPerCapita_z if CAT_ratif==0
scalar h_gdpPerCapita_z=`r(mean)'
qui sum population_z if CAT_ratif==0
scalar h_population_z=`r(mean)'	
qui sum IGO_membership if CAT_ratif==0
scalar h_IGO_membership=`r(mean)'

#delimit ;
gen sel = CR_b1*`a' + CR_b2*h_protest_ClarkRegan_logLag1 + CR_b3*h_exconst + CR_b4*h_youthBulgeln 
+ CR_b5*h_v2x_juconln + CR_b6*h_conflictYear + CR_b7*h_gdpPerCapita_z + CR_b8*h_population_z + CR_b8*h_IGO_membership 
+ CR_b10*1;

sum sel;

gen psel = normprob(sel);
sum psel;
centile psel, centile(5.0,95.0);

gen outcome1a = CR_b11*`a' + CR_b12*h_protest_ClarkRegan_logLag1 + CR_b13*h_exconst + CR_b14*h_youthBulgeln 
+ CR_b15*h_v2x_juconln + CR_b16*h_conflictYear + CR_b17*h_gdpPerCapita_z + CR_b18*h_population_z  
+ CR_b19*1;

gen prob1 = normprob(outcome1a)*(1-psel);
sum prob1;
centile prob1, centile(5.0,95.0);

gen outcome1b = CR_b20*`a' + CR_b21*h_protest_ClarkRegan_logLag1 + CR_b22*h_exconst + CR_b23*h_youthBulgeln 
+ CR_b24*h_v2x_juconln + CR_b25*h_conflictYear + CR_b26*h_gdpPerCapita_z + CR_b27*h_population_z  
+ CR_b28*1;

gen prob0 = normprob(outcome1b)*(1-psel);
sum prob0;
centile prob0, centile(5.0,95.0);

gen diff=prob1-prob0;

gen diff_pts1_1 = prob1 if `a'==1;
gen diff_pts1_5 = prob1 if `a'==5;
gen diff_pts0_1 = prob0 if `a'==1;
gen diff_pts0_5 = prob0 if `a'==5;
    
gen diff1 = diff_pts1_5 - diff_pts1_1;
gen diff0 = diff_pts0_5 - diff_pts0_1;


egen probhat0=mean(prob0);
egen probhat1=mean(prob1);
egen diffhat=mean(diff);
    
egen diff1hat=mean(diff1);
egen diff0hat=mean(diff0);
	
tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 diff_hat diff_lo diff_hi MV diff1_hat diff1_lo diff1_hi diff0_hat diff0_lo diff0_hi;  

_pctile prob0, p(5.0,95.0) ;
scalar `lo0' = r(r1);
scalar `hi0' = r(r2);  
    
_pctile prob1, p(5.0,95.0);
scalar `lo1'= r(r1);
scalar `hi1'= r(r2);  
    
_pctile diff, p(5.0,95.0);
    
scalar `diff_lo'= r(r1);
   
scalar `diff_hi'= r(r2);  

    
scalar `prob_hat0'=probhat0;
   
scalar `prob_hat1'=probhat1;
  
scalar `diff_hat'=diffhat;
    
scalar `MV' = `a';
	
post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') 
                (`diff_hat') (`diff_lo') (`diff_hi') (`MV') ;

};      


drop sel outcome1a outcome1b psel prob0 prob1 diff probhat0 probhat1 diffhat ;
drop diff_pts1_1  diff_pts1_5 diff_pts0_1 diff_pts0_5 diff1 diff0 diff1hat diff0hat;
    
    
local a=`a'+ 0.5 ;
    
  
display "." _c;
    
} ;

	
postclose mypost;                                  

use sim, clear;
	
graph twoway line prob_hat1 MV, clwidth(medium) lcolor(black) clpattern(solid)
        ||   line lo1  MV, clpattern(dash) clwidth(thin) lcolor(black)
        ||   line hi1  MV, clpattern(dash) clwidth(thin) lcolor(black)
        ||   line prob_hat0 MV, clwidth(medium) lcolor(eltblue) lpattern(solid)
        ||   line lo0  MV, clpattern(dash) clwidth(thin) lcolor(eltblue)
        ||   line hi0  MV, clpattern(dash) clwidth(thin) lcolor(eltblue)
		|| ,   
            xlabel(, labsize(4)) 
            ylabel(, labsize(4))
            yscale(noline)
            xscale(noline)
            title("", size(3))
            subtitle("" "" " ", size(3))
            xtitle("Fariss' human rights abuses scores", size(5)   )
            ytitle("Effect of CAT ratification", size(5))
            xsca(titlegap(2))
            ysca(titlegap(2))
            scheme(p2bar) graphregion(fcolor(white) lstyle(none)) 
			legend(label(4 "CAT not ratified") label(1 "CAT ratified") order(4 1));
graph export ".\Figures\Effect_CAT_fariss_SELECTION.png", replace ;


#delimit cr
*************************************************************;



log close



